package com.ideviu.webapp.action;

import java.io.Serializable;
import java.util.List;

import com.ideviu.webapp.action.BasePage;
import com.ideviu.model.TipoNegocio;
import com.ideviu.service.GenericManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component("tipoNegocioList")
@Scope("session")
public class TipoNegocioList extends BasePage implements Serializable {
    private String query;
    private GenericManager<TipoNegocio, Long> tipoNegocioManager;

    @Autowired
    public void setTipoNegocioManager(@Qualifier("tipoNegocioManager") GenericManager<TipoNegocio, Long> tipoNegocioManager) {
        this.tipoNegocioManager = tipoNegocioManager;
    }

    public void setQuery(String query) {
        this.query = query;
    }

    public String getQuery() {
        return query;
    }

    public TipoNegocioList() {
        setSortColumn("id"); // sets the default sort column
    }

    public List<TipoNegocio> getTiposNegocio() {
        if (query != null && !"".equals(query.trim())) {
            return tipoNegocioManager.search(query, TipoNegocio.class);
        } else {
            return sort(tipoNegocioManager.getAll());
        }
    }

    public String search() {
        return "success";
    }
}